package com.pesking.core.sqlparser.processor;

import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.pesking.core.exception.SystemException;
import com.pesking.core.parameter.Parameter;
import com.pesking.core.sqlparser.parameter.SqlParameter;
import com.pesking.core.sqlparser.parameter.SqlParameterProcessor;
import com.pesking.core.util.LogUtils;

public class AttachmentImageUrlSqlParameterHandler extends SqlParameterProcessor {

	@Override
	public int getOrder() {
		return 0;
	}

	@Override
	public List<String> getSqlParameterType() {
		return Arrays.asList(new String []{"IMAGE"});
	}
	@Override
	public void handle(StringBuilder sbSQL,
			Parameter parameter, List<SqlParameter> processors,SqlParameter sqlParameter) {
		String attachmentIdName = sqlParameter.getName();
		if (StringUtils.isBlank(attachmentIdName)) {
			throw new SystemException("使用方法：[IMAGE:附件ID参数名]");
		}
		String logoId = parameter.getParameter(attachmentIdName);
		if (StringUtils.isBlank(logoId)) {
			LogUtils.debug("根据参数[" + attachmentIdName + "]从参数中取不到值");
			sbSQL.append("''");
		}
		else {
			sbSQL.append("'/core/attachment/image/").append(logoId).append("'");
		}
	}

}
